import pandas as pd
import seaborn as sns
import matplotlib.pyplot as pltPandas: Intro to Series
pandas
Series
This notebook covers the Pandas Series object, which is a one-dimensional labeled array.
Series is pandas’ one-dimensional labeled array. This notebook covers creating, accessing, and operating on Series.
You will learn how to: - Create a Pandas Series - Access elements and slices - Perform arithmetic operations - View Series properties and methods - Sort and describe Series data
Importing Libraries
Import pandas and visualization libraries.
Creating a Series
Create a Series from a list with custom index labels.
my_series = pd.Series([10,20,30,40,50], index=['A', 'B', 'C', 'D', 'E'])
my_seriesA 10
B 20
C 30
D 40
E 50
dtype: int64
type(my_series)pandas.core.series.Series
Accessing Elements
Access elements by label or slice ranges.
my_series['C':'E']C 30
D 40
E 50
dtype: int64
Arithmetic Operations
Perform element-wise operations on Series.
my_series + 15A 25
B 35
C 45
D 55
E 65
dtype: int64
my_series * 25A 250
B 500
C 750
D 1000
E 1250
dtype: int64
Series Properties
Check data type, size, and shape of the Series.
my_series.dtypedtype('int64')
my_series.size5
my_series.shape(5,)
Series Methods
Use methods like head(), tail(), describe(), and sort_values() for data exploration.
my_series.head(3)A 10
B 20
C 30
dtype: int64
my_series.tail(2)D 40
E 50
dtype: int64
my_series.describe()count 5.000000
mean 30.000000
std 15.811388
min 10.000000
25% 20.000000
50% 30.000000
75% 40.000000
max 50.000000
dtype: float64
my_series.sort_values(ascending=False)E 50
D 40
C 30
B 20
A 10
dtype: int64
Best Practices
- Use meaningful index labels for clarity.
- Series operations are vectorized for performance.
- Check for NaN values with
isna().
Summary
This notebook introduced pandas Series: creation, access, operations, properties, and methods. Series are building blocks for DataFrames!